package uplb.ics.cs190.e2d.object;

import uplb.ics.cs190.e2d.display.Graphics;
import uplb.ics.cs190.e2d.math.Rectangle;

public class Background {

	protected double x;
	protected double y;
	
	private int width;
	private int height;
	
	private Rectangle clip;
	
	public Background(int width, int height) {
		this.x = 0;
		this.y = 0;
		
		this.width = width;
		this.height = height;
		
		this.clip = new Rectangle(0, 0, width, height);
	}
	
	public double getX() {
		return this.x;
	}
	
	public double getY() {
		return this.y;
	}
	
	public int getWidth() {
		return this.width;
	}
	
	public int getHeight() {
		return this.height;
	}
	
	public void setSize(int width, int height) {
		this.width = width;
		this.height = height;
		
		this.setLocation(this.x, this.y);
	}
	
	public void setLocation(double x, double y) {
		if(x > this.width - this.clip.width) {
			x = this.width - this.clip.width;
		}
		if(y > this.height - this.clip.height) {
			y = this.height - this.clip.height;
		}
		if(x < 0) {
			x = 0;
		}
		if(y < 0) {
			y = 0;
		}
		
		this.x = x;
		this.y = y;
	}	
	
	public void move(double dx, double dy) {
		this.setLocation(this.x + dx, this.y + dy);
	}
	
	public void setToCenter(int x, int y, int width, int height) {
		this.setLocation(x + (width/2) - (this.clip.width / 2),
				y + (height/2) - (this.clip.height / 2));
	}
	
	public void setToCenter(Sprite centered) {
		this.setToCenter((int) centered.getX(), (int) centered.getY(),
				centered.getWidth(), centered.getHeight());
	}
	
	public void setClip(int x, int y, int width, int height) {
		this.clip.setBounds(x, y, width, height);
	}
	
	public void setClip(Rectangle rect) {
		this.clip.setBounds(rect);
	}
	
	public Rectangle getClip() {
		return this.clip;
	}
	
	public void update(long elapsedTime) {
		
	}
	
	public void render(Graphics g) {
		this.render(g, (int) this.x, (int) this.y, this.clip.x, this.clip.y,
				(this.width < this.clip.width) ? this.width : this.clip.width,
				(this.height < this.clip.height) ? this.height : this.clip.height);
	}
	
	public void render(Graphics g, int xbg, int ybg, int x, int y
			, int width, int height) {
		
	}
}